home *** CD-ROM | disk | FTP | other *** search
- unit ntc_client_focus;
- {
- Copyright (C) 2004 - 2006 Andrew Sprott
-
- http://astronomy.crysania.co.uk
- astro@trefach.co.uk
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- }
-
- interface
-
- uses
- Windows,
- Messages,
- SysUtils,
- Variants,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- Buttons,
- StdCtrls,
- ExtCtrls,
- inifiles,
-
- ntc_client_form,
- ntc_client_network;
-
- const
- default_timeout=500;
-
- type
- Tscope_focus = class(tform)
- focus_panel: TPanel;
- focus_minus_button: TSpeedButton;
- focus_plus_button: TSpeedButton;
- speed_label: TLabel;
- speed_box: TPanel;
- first_speed_button: TSpeedButton;
- timeout_duration_label: TLabel;
- millisecond_label: TLabel;
- timeout_duration_edit: TEdit;
- stop_button: TSpeedButton;
- focus_timer: TTimer;
-
- { form functions }
- procedure formcreate(
- Sender:TObject);
-
- procedure form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
-
- procedure flip_buttons(
- toggle:boolean);
-
- { communications }
- function send_request_check(
- m:string)
- :response_type;
-
- { configuration }
- procedure load_settings;
-
- procedure save_settings;
-
- { events }
- procedure FormShow(
- Sender: TObject);
-
- procedure adjust;
-
- procedure check_activate(
- Sender: TObject);
-
- procedure speed_button_click(
- Sender: TObject);
-
- procedure stop_buttonClick(
- Sender: TObject);
-
- procedure focus_minus_buttonClick(
- Sender: TObject);
-
- procedure focus_plus_buttonClick(
- Sender: TObject);
-
- procedure enable_focus_timer;
-
- procedure focus_timerTimer(
- Sender: TObject);
-
- procedure timeout_duration_editChange(
- Sender: TObject);
-
- private
- { Private declarations }
- speed_group_index:integer;
- public
- { Public declarations }
- focus_speeds,
- start_focus_speed:integer;
- can_focus:boolean;
- focus_timeout:integer;
- { configuration }
- dimensions:dimensions_record;
-
- { events }
- procedure check_visible_and_show_hide(
- sender:tobject);
-
- procedure hide_form;
- procedure show_form;
- end;
-
- var
- scope_focus: Tscope_focus;
-
- implementation
-
- uses
- ntc_client_control;
-
- {$R *.dfm}
-
- { --------------
- form functions
- -------------- }
-
- procedure Tscope_focus.formcreate(
- Sender:TObject);
- begin
- speed_group_index:=1;
- can_focus:=false;
- flip_buttons(false);
- load_settings;
- end;
-
- procedure tscope_focus.form_close_query(
- Sender: TObject;
- var CanClose: Boolean);
- begin
- canclose:=false;
- visible:=false;
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- end;
-
- { ---------
- utilities
- --------- }
-
- function tscope_focus.send_request_check(
- m:string)
- :response_type;
- begin
- result:=scope_network.send_request_check(m);
- end;
-
- procedure Tscope_focus.flip_buttons(
- toggle:boolean);
- begin
- millisecond_label.enabled:=toggle;
- focus_minus_button.enabled:=toggle;
- focus_plus_button.enabled:=toggle;
- timeout_duration_edit.enabled:=toggle;
- speed_label.enabled:=toggle;
- speed_box.enabled:=toggle;
- first_speed_button.enabled:=toggle;
- stop_button.enabled:=toggle;
- end;
-
- { -------------
- focus control
- ------------- }
-
- procedure Tscope_focus.stop_buttonClick(
- Sender: TObject);
- begin
- send_request_check('stop_focus');
- focus_timer.enabled:=false;
- end;
-
- { -------------
- configuration
- ------------- }
-
- procedure tscope_focus.load_settings;
- begin
- ini_file:=tinifile.create(application_path+'client.ini');
- with ini_file do
- begin
- can_focus:=ReadBool('focus','can_focus',false);
- focus_timeout:=readinteger('focus','timeout',default_timeout);
- timeout_duration_edit.text:=inttostr(focus_timeout);
- start_focus_speed:=readinteger('focus','start_focus_speed',1);
- focus_speeds:=readinteger('focus','focus_speeds',2);
- if (focus_speeds>9) or
- (focus_speeds<2) then
- focus_speeds:=2;
- { form }
- scope.get_dimensions(scope_focus,@dimensions,'focus',ini_file);
- left:=dimensions.form_left;
- top:=dimensions.form_top;
- visible:=readbool('focus','visible',false);
- end;
- ini_file.free;
- end;
-
- procedure tscope_focus.save_settings;
- begin
- with ini_file do
- begin
- writeBool('focus','can_focus',can_focus);
- writeinteger('focus','timeout',focus_timeout);
- writeinteger('focus','start_focus_speed',start_focus_speed);
- writeinteger('focus','focus_speeds',focus_speeds);
- { form }
- scope.find_vdu(scope_focus,@dimensions);
- scope.write_dimensions(@dimensions,left,top,'focus',ini_file);
- writebool('focus','visible',visible);
- end;
- end;
-
- { ------
- events
- ------ }
-
- procedure Tscope_focus.FormShow(
- Sender: TObject);
- begin
- with dimensions do
- begin
- top:=form_top;
- left:=form_left;
- end;
- scope_control.update_speed_group(
- speed_box,
- first_speed_button,
- start_focus_speed,
- focus_speeds,
- speed_button_click,
- can_focus);
- end;
-
- procedure tscope_focus.adjust;
- begin
- with dimensions do
- begin
- form_top:=trunc(form_top/last_screen_height*current_height);
- form_left:=trunc(form_left/last_screen_width*current_width);
- end;
- if visible then
- show;
- end;
-
- procedure tscope_focus.check_visible_and_show_hide(
- sender:tobject);
- begin
- if visible then
- hide_form
- else
- show_form;
- scope.show_hide(sender,visible);
- end;
-
- procedure tscope_focus.hide_form;
- begin
- with dimensions do
- begin
- form_top:=top;
- form_left:=left;
- end;
- Visible:=false;
- end;
-
- procedure tscope_focus.show_form;
- begin
- Visible:=true;
- end;
-
- procedure Tscope_focus.check_activate(
- Sender: TObject);
- begin
- scope.form_activate(scope_focus,@dimensions);
- end;
-
- procedure Tscope_focus.speed_button_click(
- Sender: TObject);
- begin
- speed_group_index:=scope_control.set_slew_speed(speed_box);
- end;
-
- procedure Tscope_focus.focus_minus_buttonClick(
- Sender: TObject);
- begin
- if (scope_type=autostar_type) or (scope_type=lx200_type) then
- send_request_check('focus(speed='+inttostr(speed_group_index)+
- ',dir=-,timeout='+inttostr(focus_timeout)+')');
- end;
-
- procedure Tscope_focus.focus_plus_buttonClick(
- Sender: TObject);
- begin
- if (scope_type=autostar_type) or (scope_type=lx200_type) then
- send_request_check('focus(speed='+inttostr(speed_group_index)+
- ',dir=+,timeout='+inttostr(focus_timeout)+')');
- end;
-
- procedure tscope_focus.enable_focus_timer;
- begin
- focus_timer.interval:=focus_timeout;
- focus_timer.enabled:=true;
- end;
-
- procedure Tscope_focus.focus_timerTimer(
- Sender: TObject);
- begin
- focus_timer.enabled:=false;
- if not (send_request_check('stop_focus')>=[exit_ok]) then
- begin
- scope_control.write_status_log('Unable to stop focus');
- focus_timer.interval:=focus_timeout;
- focus_timer.enabled:=true;
- end;
- end;
-
- procedure Tscope_focus.timeout_duration_editChange(
- Sender: TObject);
- begin
- focus_timeout:=strtointdef(timeout_duration_edit.text,default_timeout);
- if focus_timeout<0 then
- begin
- focus_timeout:=default_timeout;
- timeout_duration_edit.text:=inttostr(focus_timeout);
- end;
- end;
-
- end.
-